﻿<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options" 
    
    >

    <ImageSource
        PresentationOptions:Freeze="true"
        x:Key="stopBigImage">/CodeStash.Addin.Core;component/Images/StopBig.png</ImageSource>        
        
        
    <ControlTemplate x:Key="errorTemplate">
        <Grid Name="grid">
            <Popup
                x:Name="PopupErrors"
                PlacementTarget="{Binding ElementName=grid}"
                Placement="Relative"
                AllowsTransparency="True"
                PopupAnimation="Slide"
                HorizontalOffset="20"
                StaysOpen="False"
                VerticalOffset="20">
                <Border 
                    HorizontalAlignment="Stretch"
                    BorderBrush="WhiteSmoke"
                    Width="250"
                    VerticalAlignment="Stretch"
                    Height="120"
                    BorderThickness="2"
                    CornerRadius="3">
                    <Border 
                        HorizontalAlignment="Stretch"
                        BorderBrush="Red"
                        Background="White"
                        Margin="0"
                        VerticalAlignment="Stretch"
                        Opacity="1"
                        BorderThickness="2"
                        CornerRadius="2">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition  Height="*" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <Grid 
                                Background="Transparent"
                                HorizontalAlignment="Stretch">

                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>
                                <StackPanel
                                    Orientation="Horizontal"
                                    HorizontalAlignment="Left">
                                    <Image 
                                        Source="{StaticResource stopBigImage}"
                                        Width="20"
                                        Height="20"
                                        Margin="10"
                                        VerticalAlignment="Top" />
                                    <Label
                                        VerticalAlignment="Center"
                                        FontWeight="Bold"
                                        Foreground="Red"
                                        Content="Errors:"
                                        />
                                </StackPanel>

                                <ToggleButton   
                                    Margin="5,5,15,5"
                                    Grid.Column="1"
                                    HorizontalAlignment="Right"
                                    VerticalAlignment="Center"
                                    Width="20"
                                    Style="{DynamicResource CloseableTabItemButtonStyle}"
                                    IsChecked="{Binding ElementName=PopupErrors, Path=IsOpen}"
                                    Height="20"  
                                    >
                                    <Path 
                                        Stretch="Fill"
                                        StrokeThickness="2"
                                        Stroke="Red"
                                        Fill="Red"
                                        Data="F1 M 2.28484e-007,1.33331L 1.33333,0L 4.00001,2.66669L 6.66667,6.10352e-005L 8,1.33331L 5.33334,4L 8,6.66669L 6.66667,8L 4,5.33331L 1.33333,8L 1.086e-007,6.66669L 2.66667,4L 2.28484e-007,1.33331 Z "
                                        HorizontalAlignment="Stretch"
                                        VerticalAlignment="Stretch" />
                                </ToggleButton>
                            </Grid>

                            <ScrollViewer
                                Grid.Row="1"
                                Margin="0"
                                HorizontalScrollBarVisibility="Disabled"
                               
                                VerticalScrollBarVisibility="Auto">
                                <ItemsControl
                                    Margin="5,0,0,0"
                                    BorderThickness="0"
                                    ItemsSource="{Binding ElementName=adornedElement, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}" >
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <StackPanel Orientation="Horizontal">
                                                <TextBlock
                                                    FontFamily="Wingdings 3"
                                                    Margin="0,0,5,0"
                                                    FontSize="10"
                                                    FontWeight="Normal"
                                                    Foreground="Red"
                                                    Text="u" />
                                                <TextBox 
                                                    FontSize="{DynamicResource fontSizeText}"
                                                    FontWeight="Normal"
                                                    HorizontalScrollBarVisibility="Disabled"
                                                    BorderThickness="0"
                                                    FocusVisualStyle="{x:Null}"
                                                    TextWrapping="Wrap"
                                                    IsReadOnly="True"
                                                    Foreground="Red" 
                                                    Height="Auto"
                                                    Width="210"
                                                    Text="{Binding Mode=OneWay}" />
                                            </StackPanel>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>
                            </ScrollViewer>
                        </Grid>
                    </Border>
                </Border>
            </Popup>

            <AdornedElementPlaceholder Name="adornedElement" />

            <Border 
                CornerRadius="0"
                BorderBrush="Red"
                BorderThickness="1"
                VerticalAlignment="Stretch"
                HorizontalAlignment="Stretch"/>

            <ToggleButton 
                    HorizontalAlignment="Right"
                    VerticalAlignment="Top"
                    Margin="0,-5,-5,0"
                    Width="15"
                    Height="15"
                    IsChecked="{Binding ElementName=PopupErrors, Path=IsOpen}">

                <Path Data="M120,40 L159.5,39.5 159.5,63.5 z" 
                      HorizontalAlignment="Right" Height="9" 
                      Width="9" Margin="0,5,5,0" Stretch="Fill" Stroke="Red" 
                      VerticalAlignment="Top" 
                      Fill="Red"/>


                <ToggleButton.Template>
                    <ControlTemplate TargetType="ButtonBase">
                        <ContentPresenter Content="{TemplateBinding Content}"/>
                    </ControlTemplate>
                </ToggleButton.Template>
            </ToggleButton>
        </Grid>
    </ControlTemplate>

</ResourceDictionary>